package com.tfjybj.itoo.exam.provider.controller;

import org.apache.dubbo.config.annotation.Reference;;
import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.exam.provider.service.CourseScheduleService;
import com.tfjybj.itoo.teach.FacadeApi.CourseScheduleApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * CourseScheduleController
 * courseSchedule表
 *
 * @author 杨江涛
 * @version 2.0.0
 * @since 2.0.0 2018-11-15 10:35:56
 */
@Api(tags = {"courseSchedule表接口"})
@RequestMapping(value = "/courseSchedule")
@RestController
public class CourseScheduleController {

    @Resource
    private CourseScheduleService courseScheduleService;

    @Reference(check = false)
    private CourseScheduleApi courseScheduleApi;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model CourseScheduleModel
     * @return 添加的结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody com.tfjybj.itoo.teach.model.CourseScheduleModel model) {
        if (StringUtils.isEmpty(model.getClassId())) {
            return ItooResult.build(ItooResult.FAIL, "classId为空");
        }
        if (StringUtils.isEmpty(model.getTeachClassId())) {
            return ItooResult.build(ItooResult.FAIL, "teachClassId为空");
        }
        if (StringUtils.isEmpty(model.getCellTimeId())) {
            return ItooResult.build(ItooResult.FAIL, "cellTimeId为空");
        }
        if (StringUtils.isEmpty(model.getWeekId())) {
            return ItooResult.build(ItooResult.FAIL, "weekId为空");
        }
        if (StringUtils.isEmpty(model.getRoomId())) {
            return ItooResult.build(ItooResult.FAIL, "roomId为空");
        }
        if (StringUtils.isEmpty(model.getTeacherTeachId())) {
            return ItooResult.build(ItooResult.FAIL, "teacherTeachId为空");
        }
        if (StringUtils.isEmpty(model.getSemesterId())) {
            return ItooResult.build(ItooResult.FAIL, "semesterId为空");
        }
        com.tfjybj.itoo.teach.entity.CourseScheduleEntity courseScheduleEntity = new com.tfjybj.itoo.teach.entity.CourseScheduleEntity();
        BeanUtils.copyProperties(model, courseScheduleEntity);
        courseScheduleApi.create(courseScheduleEntity);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        courseScheduleApi.delete(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiImplicitParam(name = "ids", value = "ids", dataType = "List<String>", required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        courseScheduleApi.deleteByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model CourseScheduleModel
     * @return 修改后的结果
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id修改courseSchedule")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody com.tfjybj.itoo.teach.model.CourseScheduleModel model) {
        if (StringUtils.isEmpty(model.getClassId())) {
            return ItooResult.build(ItooResult.FAIL, "classId为空");
        }
        if (StringUtils.isEmpty(model.getTeachClassId())) {
            return ItooResult.build(ItooResult.FAIL, "teachClassId为空");
        }
        if (StringUtils.isEmpty(model.getCellTimeId())) {
            return ItooResult.build(ItooResult.FAIL, "cellTimeId为空");
        }
        if (StringUtils.isEmpty(model.getWeekId())) {
            return ItooResult.build(ItooResult.FAIL, "weekId为空");
        }
        if (StringUtils.isEmpty(model.getRoomId())) {
            return ItooResult.build(ItooResult.FAIL, "roomId为空");
        }
        if (StringUtils.isEmpty(model.getTeacherTeachId())) {
            return ItooResult.build(ItooResult.FAIL, "teacherTeachId为空");
        }
        if (StringUtils.isEmpty(model.getSemesterId())) {
            return ItooResult.build(ItooResult.FAIL, "semesterId为空");
        }
        com.tfjybj.itoo.teach.entity.CourseScheduleEntity courseScheduleEntity = new com.tfjybj.itoo.teach.entity.CourseScheduleEntity();
        BeanUtils.copyProperties(model, courseScheduleEntity);
        courseScheduleApi.modify(courseScheduleEntity);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找CourseSchedule
     *
     * @param id 主键id
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})
    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        com.tfjybj.itoo.teach.entity.CourseScheduleEntity courseScheduleEntity = courseScheduleApi.findById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", courseScheduleEntity);
    }

    /**
     * 分页查询所有CourseSchedule
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "分页查询所有CourseSchedule")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo", value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                   @ApiParam(name = "pageSize", value = "页数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<com.tfjybj.itoo.teach.entity.CourseScheduleEntity> courseSchedules = courseScheduleApi.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", courseSchedules);
    }

    /**
     * 根据班级_id模糊查询courseSchedule
     *
     * @param classId  班级_id
     * @param pageNo   页码
     * @param pageSize 页数
     * @return 模糊查询的courseSchedule
     * @author 杨江涛
     * @since 2.0.0 2018-11-15 10:35:56
     */
    @ApiOperation(value = "根据班级_id模糊查询courseSchedule", notes = "分页根据班级_id模糊查询courseSchedule")
    @GetMapping(value = "queryCourseScheduleByLikeClassId/{pageNo}/{pageSize}")
    public ItooResult queryCourseScheduleByLikeClassId(@RequestParam(required = false, defaultValue = "") String classId,
                                                       @ApiParam(value = "页码", required = true, example = "1") @PathVariable Integer pageNo,
                                                       @ApiParam(value = "记录数", required = true, example = "10") @PathVariable Integer pageSize) {
        PageInfo<com.tfjybj.itoo.teach.entity.CourseScheduleEntity> courseScheduleList = courseScheduleApi.queryCourseScheduleByLikeClassId(classId, pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", courseScheduleList);
    }
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */

    /**
     * 根据id查找CourseSchedule
     *
     * @param courseId 主键courseId
     * @author 杨江涛
     * @since 2.0.0  2018-11-23 20:42:04
     */
    @ApiOperation(value = "根据courseId查询课程名称")
    @GetMapping(value = {"/findByCourseId/{courseId}"})
    public ItooResult findByCourseId(@ApiParam(value = "课程courseId", required = true) @PathVariable String courseId) {
        if (courseId == null) {
            return ItooResult.build(ItooResult.FAIL, "课程ID为空");
        } else {
            try {
                String strCourseSchedule = courseScheduleApi.findByCourseId(courseId);
                return ItooResult.build(ItooResult.SUCCESS, "查询成功", strCourseSchedule);
            } catch (Exception e) {
                return ItooResult.build(ItooResult.FAIL, "查询失败");
            }

        }

    }

    /**
     * 无参查询查找CourseSchedule
     *
     * @return courseScheduleEntity
     * @author 杨江涛
     * @since 2.0.0  2018-11-24 10:15:37
     */
    @ApiOperation(value = "无参查询所有课程名称")
    @GetMapping(value = {"/findCourse"})
    public ItooResult findCourse() {
        List<com.tfjybj.itoo.teach.entity.CourseScheduleEntity> courseScheduleEntityList = courseScheduleApi.findCourse();
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", courseScheduleEntityList);
    }
}
